<?php

namespace app\api\controller;

use app\admin\model\litestore\Litestoreorder;
use app\common\controller\Api;
use think\Config;


/**
 * 分享中心接口
 */
class SharingCenter extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 查看分享链接，分佣订单，收益，提现
     */
    public function index()
    {
        //游客不允许请求此接口
        $user_info = $this->auth->getUser();
        if(empty($user_info)){
            return $this->error('Please login');
        }
        $share_url = request()->domain().'/#/collections/0/blogger/'.$user_info['id'];

        $page = $this->request->request('page');
        // 筛选条件
        $filter['parent_user_id'] = $user_info['id'];
        $model_temp = new Litestoreorder();
        $listdata = $model_temp->with(['goods'])
            ->where($filter)->order('id desc')
            ->paginate(8, false, [ 'page' => $page ])
            ->each(function($item){
                foreach ($item->goods as $k=>$v){
                    $v['image'] = cdnurl(explode(",",$v['images'])[0], true);
                }
            });

        $pagedata = $listdata;
        $this->success('', [
            'money' => $user_info['money'],
            'share_url' => $share_url,
            'pagedata' => $pagedata,
        ]);
    }
}
